package tsing.javase.designpattern.factory_pattern.simple_factory;

/**
 * @Author Tsing/吴清平
 * @Date 2022/10/24 16:44
 * @Version 1.0
 *
 * 简单工厂模式：通过工厂来创建对象
 */
public class ShapeFactory {

    public Shape getShape(String shapeType){

        if(shapeType ==null || "".equals(shapeType)){
            return null;
        }

        if("Circle".equals(shapeType)){
            return new Circle();
        }
        if("Square".equals(shapeType)){
            return new Square();
        }
        if("Rectangle".equals(shapeType)){
            return new Rectangle();
        }

        return null;
    }

    public static void main(String[] args) {
        ShapeFactory shapeFactory = new ShapeFactory();
        shapeFactory.getShape("Circle").draw();
        shapeFactory.getShape("Square").draw();
        shapeFactory.getShape("Rectangle").draw();
    }
}
